package main

import "fmt"

/**
	多态：同一个接口，传入不同的实例，执行不同的操作
 */
func main() {
	stu := student{
		name: "张三",
		age: 18,
		score: 80,
	}
	teacher := teacher{
		name:    "老师",
		age:     28,
		subject: "数学",
	}

	//[top] 通过多态调用对象方法
	sayHello(&stu)
	sayHello(&teacher)


	//stu.sayHi()
	//teacher.sayHi()

	//var human Humaner
	////将对象信息赋值给接口变量
	//human = &stu
	//human.sayHi()
	//
	//human = &teacher
	//human.sayHi()


}

type student struct {
	name	string
	age		int
	score	int
}

type teacher struct {
	name	string
	age		int
	subject	string
}
type Humaner interface {
	sayHi()
}

func (stu *student) sayHi() {
	fmt.Printf("大家好，我是%s，今年%d 岁，我的分数是 %d\n",stu.name,stu.age,stu.score)
}

func (teacher *teacher) sayHi() {
	fmt.Printf("大家好，我是%s，今年%d 岁，我的学科是 %s",teacher.name,teacher.age,teacher.subject)
}

//多态实现
func sayHello(h Humaner){
	h.sayHi()
}